package ttpasi.jgenere.chaocipher.crack_hack;

//import static ttpasi.jgenere.chaocipher.testutils.AssertUtils.LINE_SEPARATOR;
//import static ttpasi.jgenere.chaocipher.testutils.FormatExhibitData.read;
//
//import java.io.FileReader;
//import java.util.List;
//import java.util.Scanner;
//
//import ttpasi.jgenere.chaocipher.Chaocipher;
//import ttpasi.jgenere.chaocipher.HoleFinder;
//import ttpasi.jgenere.chaocipher.SequenceFinder;

public class Exhibit4Crack
{
//  static void findMinSequencesWithHoles(int holesCount) throws Exception
//  {
//    String lt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//    String rt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//    String ex1Ct = read("test-data/chaocipher-exhibit-4.to-crack.ct.txt");
//    String ex1Pt = read("test-data/chaocipher-exhibit-4.to-crack.pt.txt");
//    SequenceFinder sf = new SequenceFinder(lt, rt, ex1Ct, ex1Pt);
//    List sequences = sf.findMinSequencesWithHoles(holesCount);
//    int sequenceSize = sequences.size();
//    System.out.println(sequenceSize + " sequences found.");
//    for (int i = 0; i < sequenceSize; i++)
//    {
//      SequenceFinder.Sequence sequence = (SequenceFinder.Sequence) sequences.get(i);
//      System.out.println("----");
//      System.out.println("length: " + sequence._ct.length());
//      System.out.println(sequence._ct);
//      System.out.println(sequence._pt);
//      HoleFinder hf = new HoleFinder(sequence._ct, sequence._pt);
//      hf.logHoles();
//    }
//  }
//
//  public static void main(String[] args) throws Exception
//  {
//    //    findMinSequencesWithHoles(5);
//    //    4 sequences found.
//    //    ----
//    //    length: 358
//    //    CKBEVEFRAOMFABMQDTVWBRLRQUQERRGEGALISYEMBDUKVIVVOXMEDBWXZVOIVGFHKDJQLVWFYJOLKHVHKYPPIDKIGNYREXDOGVSPETTSQWNZWLJOAEIFBKYHNOFBARDIEPCHVHGONVJHLZHDRYYFUXJSZDSWIKREUIVCTVOPPOWWDKDIFDYBCEKLOPMFSUTRDASFCSEDKDHBSTKHPGETYEOCESNTEXDAOFPJAWPYTZXZADCQZSQBQVHIGMMOIYFKQFHFNNEADKGUKIEIHEAVSTHORHCUPQHEFVXRTLYBZZCMHDVVBXFTWCSHKIWAGTVJVURACNLPIWDVSBJIVGUXDPJHLVCBRGJMDMLOHX
//    //    THEPHILIPPINESQTHEPEOPLESOFASIAFOUNDTHEIROPPORTUNITYINTHEWARJUSTPASTTOTHROWOFFTHESHACKLESOFCOLONIALISMQANDNOWSEETHEDAWNOFNEWOPPORTUNITYQAHERETOFOREUNFELTDIGNITYQANDTHESELFXRESPECTOFPOLITICALFREEDOMZMUSTERINGHALFOFTHEEARTHJSPOPULATIONANDSIXTYPERCENTOFITSNATURALRESOURCESQTHESEPEOPLESARERAPIDLYCONSOLIDATINGANEWFORCEQBOTHMORALANDMATERIALQWITHWHICHTORAISETHELIV
//    //    holes at: 1[K,H], 2[B,E], 3[E,P], 6[F,L], 35[I,D], 
//    //    ----
//    //    length: 357
//    //    KBEVEFRAOMFABMQDTVWBRLRQUQERRGEGALISYEMBDUKVIVVOXMEDBWXZVOIVGFHKDJQLVWFYJOLKHVHKYPPIDKIGNYREXDOGVSPETTSQWNZWLJOAEIFBKYHNOFBARDIEPCHVHGONVJHLZHDRYYFUXJSZDSWIKREUIVCTVOPPOWWDKDIFDYBCEKLOPMFSUTRDASFCSEDKDHBSTKHPGETYEOCESNTEXDAOFPJAWPYTZXZADCQZSQBQVHIGMMOIYFKQFHFNNEADKGUKIEIHEAVSTHORHCUPQHEFVXRTLYBZZCMHDVVBXFTWCSHKIWAGTVJVURACNLPIWDVSBJIVGUXDPJHLVCBRGJMDMLOHX
//    //    HEPHILIPPINESQTHEPEOPLESOFASIAFOUNDTHEIROPPORTUNITYINTHEWARJUSTPASTTOTHROWOFFTHESHACKLESOFCOLONIALISMQANDNOWSEETHEDAWNOFNEWOPPORTUNITYQAHERETOFOREUNFELTDIGNITYQANDTHESELFXRESPECTOFPOLITICALFREEDOMZMUSTERINGHALFOFTHEEARTHJSPOPULATIONANDSIXTYPERCENTOFITSNATURALRESOURCESQTHESEPEOPLESARERAPIDLYCONSOLIDATINGANEWFORCEQBOTHMORALANDMATERIALQWITHWHICHTORAISETHELIV
//    //    holes at: 1[B,E], 2[E,P], 5[F,L], 14[Q,T], 34[I,D], 
//    //    ----
//    //    length: 356
//    //    BEVEFRAOMFABMQDTVWBRLRQUQERRGEGALISYEMBDUKVIVVOXMEDBWXZVOIVGFHKDJQLVWFYJOLKHVHKYPPIDKIGNYREXDOGVSPETTSQWNZWLJOAEIFBKYHNOFBARDIEPCHVHGONVJHLZHDRYYFUXJSZDSWIKREUIVCTVOPPOWWDKDIFDYBCEKLOPMFSUTRDASFCSEDKDHBSTKHPGETYEOCESNTEXDAOFPJAWPYTZXZADCQZSQBQVHIGMMOIYFKQFHFNNEADKGUKIEIHEAVSTHORHCUPQHEFVXRTLYBZZCMHDVVBXFTWCSHKIWAGTVJVURACNLPIWDVSBJIVGUXDPJHLVCBRGJMDMLOHX
//    //    EPHILIPPINESQTHEPEOPLESOFASIAFOUNDTHEIROPPORTUNITYINTHEWARJUSTPASTTOTHROWOFFTHESHACKLESOFCOLONIALISMQANDNOWSEETHEDAWNOFNEWOPPORTUNITYQAHERETOFOREUNFELTDIGNITYQANDTHESELFXRESPECTOFPOLITICALFREEDOMZMUSTERINGHALFOFTHEEARTHJSPOPULATIONANDSIXTYPERCENTOFITSNATURALRESOURCESQTHESEPEOPLESARERAPIDLYCONSOLIDATINGANEWFORCEQBOTHMORALANDMATERIALQWITHWHICHTORAISETHELIV
//    //    holes at: 1[E,P], 2[V,H], 4[F,L], 13[Q,T], 33[I,D], 
//    //    ----
//    //    length: 355
//    //    EVEFRAOMFABMQDTVWBRLRQUQERRGEGALISYEMBDUKVIVVOXMEDBWXZVOIVGFHKDJQLVWFYJOLKHVHKYPPIDKIGNYREXDOGVSPETTSQWNZWLJOAEIFBKYHNOFBARDIEPCHVHGONVJHLZHDRYYFUXJSZDSWIKREUIVCTVOPPOWWDKDIFDYBCEKLOPMFSUTRDASFCSEDKDHBSTKHPGETYEOCESNTEXDAOFPJAWPYTZXZADCQZSQBQVHIGMMOIYFKQFHFNNEADKGUKIEIHEAVSTHORHCUPQHEFVXRTLYBZZCMHDVVBXFTWCSHKIWAGTVJVURACNLPIWDVSBJIVGUXDPJHLVCBRGJMDMLOHX
//    //    PHILIPPINESQTHEPEOPLESOFASIAFOUNDTHEIROPPORTUNITYINTHEWARJUSTPASTTOTHROWOFFTHESHACKLESOFCOLONIALISMQANDNOWSEETHEDAWNOFNEWOPPORTUNITYQAHERETOFOREUNFELTDIGNITYQANDTHESELFXRESPECTOFPOLITICALFREEDOMZMUSTERINGHALFOFTHEEARTHJSPOPULATIONANDSIXTYPERCENTOFITSNATURALRESOURCESQTHESEPEOPLESARERAPIDLYCONSOLIDATINGANEWFORCEQBOTHMORALANDMATERIALQWITHWHICHTORAISETHELIV
//    //    holes at: 1[V,H], 3[F,L], 10[B,S], 12[Q,T], 32[I,D], 
//
//    // find the alphabets
//    //                char[] ct = "EVEFRAOMFABMQDTVWBRLRQUQERRGEGALISYEMBDUKVIVVOXMEDBWXZVOIVGFHKDJQLVWFYJOLKHVHKYPPIDKIGNYREXDOGVSPETTSQWNZWLJOAEIFBKYHNOFBARDIEPCHVHGONVJHLZHDRYYFUXJSZDSWIKREUIVCTVOPPOWWDKDIFDYBCEKLOPMFSUTRDASFCSEDKDHBSTKHPGETYEOCESNTEXDAOFPJAWPYTZXZADCQZSQBQVHIGMMOIYFKQFHFNNEADKGUKIEIHEAVSTHORHCUPQHEFVXRTLYBZZCMHDVVBXFTWCSHKIWAGTVJVURACNLPIWDVSBJIVGUXDPJHLVCBRGJMDMLOHX".toCharArray();
//    //                char[] pt = "PHILIPPINESQTHEPEOPLESOFASIAFOUNDTHEIROPPORTUNITYINTHEWARJUSTPASTTOTHROWOFFTHESHACKLESOFCOLONIALISMQANDNOWSEETHEDAWNOFNEWOPPORTUNITYQAHERETOFOREUNFELTDIGNITYQANDTHESELFXRESPECTOFPOLITICALFREEDOMZMUSTERINGHALFOFTHEEARTHJSPOPULATIONANDSIXTYPERCENTOFITSNATURALRESOURCESQTHESEPEOPLESARERAPIDLYCONSOLIDATINGANEWFORCEQBOTHMORALANDMATERIALQWITHWHICHTORAISETHELIV".toCharArray();
//    //    String lt = "..........................";
//    //    String rt = "..........................";
//    //    int[] holes = {1, 3, 10, 12, 32};
//    //    Foo.initializeLogging();
//    //    Foo.findTheAlphabets(0, ct, pt, lt, rt, holes);
//    //    <findTheAlphabets>
//    //    position: 355
//    //    XVGTRFBQUDINLECMYWSKZHAJOP
//    //    XOTUWMLENGHPBQYSDZJICAKRFV
//    //    alphabets found
//
//    //        char[] left = "XVGTRFBQUDINLECMYWSKZHAJOP".toCharArray();
//    //        char[] right = "XOTUWMLENGHPBQYSDZJICAKRFV".toCharArray();
//
//    // roll the alphabets back to position 1
//    //    Foo.rollBack(left, right, ct, pt, 354);
//    //    System.out.println(left); //  EDGXNIPBUJCFYKWTSLQZOAHRVM
//    //    System.out.println(right); // ILSFZEUTMBRCKYDJNGWQOXAVHP
//
//    //           Z            N
//    //    String lt = "EKDGXNIPBUJCFYWTSLQZOAHRVM";
//    //    String rt = "PILYSFZEUTMBRCKDJNGWQOXAVH";
//    //
//    //    Chaocipher chaocipher = new Chaocipher(lt, rt);
//    //    String ciphertext = chaocipher.encipher(new String(pt));
//    //    System.out.println(ciphertext);
//    //    String plaintext = chaocipher.decipher(new String(ct));
//    //    System.out.println(plaintext);
//
//    // roll the alphabets all the way back to position 1 of the entire text
//    //    String ct = read("test-data/chaocipher-exhibit-4.cracked.ct.txt");
//    //    String pt = read("test-data/chaocipher-exhibit-4.cracked.pt.txt");
//    //    Foo.rollBack(left, right, ct.toCharArray(), pt.toCharArray(), 779);
//    //    System.out.println(left); //  VZMBCPFGTHXIWYJKLADESNOQRU
//    //    System.out.println(right); // OPGRSTUKVWYZAQFCDLXEHIJMNB
//
//    //           Z            N
//    String lt = "VYZMBCPFGTHXIWJKLADESNOQRU"; // VYZMBCPFGTHXIWJKLADESNOQRU
//    String rt = "BOPQGRSTUKVWYZAFCDLXEHIJMN"; // BOPQGRSTUKVWYZAFCDLXEHIJMN
//    Chaocipher chaocipher = new Chaocipher(lt, rt);
//    String ciphertext = chaocipher.encipher(read("test-data/chaocipher-exhibit-4.to-crack.pt.txt"));
//    System.out.println(ciphertext);
//    String plaintext = chaocipher.decipher(read("test-data/chaocipher-exhibit-4.to-crack.ct.txt"));
//    System.out.println(plaintext);
//  }
}